//
//  StockGrapth.h
//  iStock Global
//
//  Created by Andy on 2010/10/5.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"
#import "DataObject.h" 
#import "GraphSetup.h"
#import "SplitViewDelegate.h"
//觸控方法敏感度
#define Y_TOLERANCE 5
#define X_TOLERANCE 5

#define kminlength 1
//#define kmaxoffset 5

typedef enum  {
	S0,
	S1
} STATE;

@protocol GraphObjectDelgete

-(void)NextDrawGraph:(NSUInteger)indexrow;  
-(void)PreviousDrawGraph:(NSUInteger)indexrow;  
-(void)SegmetnctlChange:(NSString *)Cdwm indexr:(NSUInteger)indexrow;


@end


@interface StockGrapth : UIViewController <SplitViewDelegate_Delgete,GraphSetupDelgete,CPTPlotDataSource,CPTPlotSpaceDelegate,CPLayerHostEvent, CPTBarPlotDelegate>{
	id <GraphObjectDelgete> delgete;	
	
	NSString *graph_dwm;//日週月
	
   UIActivityIndicatorView *ActivityIndicator;
    
	CGPoint startLocation, endLocation;
	NSTimeInterval startTime, endTime;
	STATE			state;	
	
	//日週月線切換物件
	UISegmentedControl *segmetnctl;	
	
	//增加笑傲曲線
	NSMutableArray *plotIdentfy;
	NSMutableArray *dataForPlot_Array;
	
	//走勢圖物件
	CPTXYGraph * graph;
	CPTGraphHostingView *layerHost;	
	
	int index_array_layer_lin;
	NSMutableArray *array_layer_lin;
	 
	CPTTextLayer *layer_lin1L; //第1行左邊
	/*
	CPTextLayer *layer_lin2L; //第2行左邊
	CPTextLayer *layer_lin3L; //第3行左邊
	CPTextLayer *layer_lin4L; //第4行左邊	
	*/
	CPTTextLayer *layer_lin1M;
	CPTTextLayer *layer_lin1R;
	
	CPTTextLayer *layer_year;//左邊 顯示最左邊的年份
	CPTTextLayer *layer_MonthDay; //右邊 最接近日期
	
	//股票資料物件
	DataObject *stockdata;
    
	//計算走勢圖位置變數
	NSDecimalNumber *x0;
	NSDecimalNumber *x1;
	NSDecimalNumber *x2;
	
	NSDecimalNumber *xVolRange;
	NSDecimalNumber *Volrange;
	//觸控
	CGPoint gestureStartPoint;
	CGFloat originaDistance;
	
	//k線圖設定
	int  KBarLength; //圖形上顯示幾根K線數量
	int KBarSartLocation;//x軸上起始位置
	int KBarSartLocation_limitLeft; //極限位置
	int KBarSartLocation_move; //移動速度
	
    int graph_show_length;
    
    UIToolbar *toolbar;   
    id AppleDeglate;
    
    UIPopoverController* popController;  
       
    
}
@property(assign) id AppleDeglate;
@property (nonatomic,assign) NSString * graph_dwm;
@property (nonatomic,assign) CPTXYGraph * graph;
@property (nonatomic, assign) CPTGraphHostingView *layerHost;
@property(assign) id <GraphObjectDelgete> delgete;

//取得股價資料方法
-(void)get_stockdata:(DataObject *)astockdata;
//重新繪圖
-(void)redrawChart:(BOOL)isreset;
-(void)resetLocationData;
//增加笑傲曲線方法
-(NSMutableDictionary *)buildLF:(NSString *)identfilers 
					 blineColor:(CPTColor *)blinecolor
					 slineColor:(CPTColor *)slinecolor
					  blinewith:(CGFloat)bwlinewith
					  slinewith:(CGFloat)swlinewith;


-(CPTScatterPlot *)addnewplot:(CPTXYGraph *)grapha identifier:(NSString *)ident andlinecolor:(CPTColor *)linecolor andLineWith:(CGFloat)linef; 
-(void) segmentChanged:(id)sender;

//觸控方法
-(void)Horizontal_swipe_RL;
-(void)Horizontal_swipe_LR;
-(void)Vertical_swipe_UD;
-(void)Vertical_swipe_DU;
-(void)touchend;
-(void)twofing_clsoe;
-(void)twofin_out;
-(void)showInfo;
-(void)stopActivityIndicator;

-(NSDecimalNumber *)turnNSDecimalNumber:(NSDecimalNumber *)inp;
-(NSDecimalNumber *)HighPrice:(DataObject *)aDataObject startX:(int)astartX count:(int)acount;
-(NSDecimalNumber *)LowPrice:(DataObject *)aDataObject startX:(int)astartX count:(int)acount;
-(NSDecimalNumber *)HighVolume:(DataObject *)aDataObject startX:(int)astartX count:(int)acount;
-(NSDecimalNumber *)LowVolume:(DataObject *)aDataObject startX:(int)astartX count:(int)acount;
-(NSString *)LableDateString:(int)Index;
-(NSString *)LableDateStringYear:(int)Index;
-(void)graph_Setup_Detail:(int)lastindex;
-(void)showLeft_layer:(NSMutableDictionary *)aparaobject fdata:(NSMutableDictionary *)lastfdata graph_line:(CPTTextLayer *)cptextline;

-(void)resize_graph_frame;
@end

